﻿using System.Numerics;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using static System.Net.Mime.MediaTypeNames;

namespace homework8
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private Database database;
        private List<Data> data;
        public MainWindow()
        {
            database = new Database();
            InitData();
            InitializeComponent();
            

        }
        private void InitData() {
            database.CreateTable();
            database.InsertData();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            database.Select(((Button)sender).Name);
            data=database.GetData;
            datagrid.ItemsSource = data;
            scene2.Visibility=Visibility.Visible;
        }

        private void Back_Click(object sender, RoutedEventArgs e)
        {
            database.reSet();
            datagrid.ItemsSource = null;
            scene2.Visibility = Visibility.Hidden;
            Retry.Visibility = Visibility.Hidden;
            Submit.Visibility = Visibility.Visible;
            score.Text = string.Empty;
        }

        private void Submit_Click(object sender, RoutedEventArgs e)
        {
            int Correct = 0;
            for (int i = 0; i < 5; i++)
            {
                string answer = (datagrid.Columns[1].GetCellContent(datagrid.Items[i]) as TextBlock).Text;
                if (answer.Equals(data[i].English))
                {
                    (datagrid.Columns[2].GetCellContent(datagrid.Items[i]) as TextBlock).Text = "√";
                    Correct++;
                }
                else
                    (datagrid.Columns[2].GetCellContent(datagrid.Items[i]) as TextBlock).Text = "X";
            }
            score.Text = "Score:"+(20 * Correct).ToString();
        }

        private void Answer_Click(object sender, RoutedEventArgs e)
        {
            Submit.Visibility = Visibility.Hidden;
            for (int i = 0; i < 5; i++)
            {
                
                (datagrid.Columns[1].GetCellContent(datagrid.Items[i]) as TextBlock).Text = data[i].English;
                
            }
            Retry.Visibility = Visibility.Visible;
        }

        private void Retry_Click(object sender, RoutedEventArgs e)
        {
            score.Text = string.Empty;
            for (int i = 0; i < 5; i++)
            {

                (datagrid.Columns[1].GetCellContent(datagrid.Items[i]) as TextBlock).Text = string.Empty;
                (datagrid.Columns[2].GetCellContent(datagrid.Items[i]) as TextBlock).Text = string.Empty;
            }
            Retry.Visibility = Visibility.Hidden;
            Submit.Visibility = Visibility.Visible;
        }
    }
}